package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetMealServer;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐相关接口")
public class SetMealController {
    @Autowired
    private SetMealServer setMealServer;

    @GetMapping("/page")
    @ApiOperation("套餐分页查询")
    public Result<PageResult> selectMealForPages(SetmealPageQueryDTO setmealPageQueryDTO) {
        return Result.success(setMealServer.select(setmealPageQueryDTO));
    }

    @PostMapping
    @ApiOperation("新增套餐")
    public Result addSetmeal(@RequestBody SetmealDTO setmealDTO) {
        setMealServer.addSetMealAndDishes(setmealDTO);
        return Result.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询套餐")
    public Result<SetmealVO> selectSetmealById(@PathVariable Long id) {
        return Result.success(setMealServer.getMealById(id));
    }

    @PostMapping("/status/{status}")
    @ApiOperation("套餐起售，停售")
    public Result updateSetmealStatus(@PathVariable Integer status,Long id) {
        setMealServer.changeStatus(id, status);
        return Result.success();
    }

    @PutMapping
    @ApiOperation("修改套餐")
    public Result updateSetmeal(@RequestBody SetmealDTO setmealDTO) {
        setMealServer.updateMeal(setmealDTO);
        return Result.success();
    }

    @DeleteMapping
    @ApiOperation("批量删除套餐")
    public Result deleteSetmeal(@RequestParam List<Long> ids) {
        setMealServer.delete(ids);
        return Result.success();
    }
}
